package br.pucrio.inf.csm.matchers.schema;

import br.pucrio.inf.csm.Attribute;
import br.pucrio.inf.csm.Catalog;
import br.pucrio.inf.csm.GenericMatrix;
import br.pucrio.inf.csm.IMatch;
import br.pucrio.inf.csm.QueryOccurrenceMatrix;

/**
 * Implements a catalog schema matcher, using the inter-site schema matching
 * described in [WANG, 2005] for attribute matching; and the strategy described
 * in [BRAUNER, 2006] for taxonomy matching. This implies the use of a global
 * schema.
 * 
 * @author agazola
 * 
 */
public class VectorSimilaritySchemaMatcher extends AbstractCatalogSchemaMatcher {

	private Catalog globalCatalog;

	public VectorSimilaritySchemaMatcher(Catalog globalCatalog) {
		this.globalCatalog = globalCatalog;
	}

	@Override
	public IMatch<Attribute> matchAttributes(Catalog catalog1, Catalog catalog2) {
		// occurrence matrix for [schema1 x global schema]
		QueryOccurrenceMatrix matrix1 = buildOccurrenceMatrix(globalCatalog,
				catalog1);
		// occurrence matrix for [schema2 x global schema]
		QueryOccurrenceMatrix matrix2 = buildOccurrenceMatrix(globalCatalog,
				catalog2);

		GenericMatrix similarityMatrix = matrix1
				.computeSimilarityMatrix(matrix2);

		return similarityMatrix.findMatches();
	}
}
